﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using System.Linq;
using System.Data.Linq;
using System.Data;
using ProgramDemoForModelling.CheckValidation;
using Manage_Garage_Car;
using System.Reflection;

namespace ProgramDemoForModelling
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : RibbonWindow
    {
        ProgramDemoForModellingDataContext m_database = new ProgramDemoForModellingDataContext("server=NKT_PC;database=QUANLYGARA;uid=sa;pwd=2281994");

        CheckValidationCar m_checkValidationDSHX = new CheckValidationCar();

        CheckValidationCarStyle m_checkValidationDSX = new CheckValidationCarStyle();

        CheckValidationCar m_checkValidationTNBT = new CheckValidationCar();

        Utilities m_utilities = new Utilities();

        int m_tabCurrentIndex = -1;

        public MainWindow()
        {
            InitializeComponent();
        }

        #region Tab Main Control

        private void tabControlMain_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int tabIndex = (sender as TabControl).SelectedIndex;

            if (tabIndex == m_tabCurrentIndex)
            {
                return;
            }

            m_tabCurrentIndex = tabIndex;
            switch (tabIndex)
            {
                case 0:
                    DataTable dt = new DataTable();
                    dt = m_utilities.LINQToDataTable(m_database.LOADHIEUXE());
                    dataGrid1DSHX.ItemsSource = dt.DefaultView;
                    break;
                case 1:
                    cbxCarStyleDSX.DataContext = m_database.GETTENHIEUXE();
                    cbxCarStyleDSX.SelectedIndex = 0;
                    dataGrid1DSX.ItemsSource = m_database.LOADXE();
                    break;
                case 2:
                    cbxCarStyleTNBT.DataContext = m_database.LOADHIEUXE();
                    cbxCarStyleTNBT.SelectedIndex = 0;
                    dataGrid1TNBT.ItemsSource = m_database.LOADPHIEUTIEPNHANXE();
                    CheckTNBT();
                    break;
                case 3:
                    cbxNumberPlateDSPSC.DataContext = m_database.GETBIENSO();
                    cbxNumberPlateDSPSC.SelectedIndex = 0;
                    dataGrid1DSPSC.ItemsSource = m_database.LOADPHIEUTIEPNHANXE();
                    break;
                default:
                    break;
            }
        }

        #endregion

        #region Tab DSHX

        #region Process Input

        private void tbxNameCarStyleDSHX_LostFocus(object sender, RoutedEventArgs e)
        {
            if (tbxNameCarStyleDSHX.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationDSX.CheckNameCarStyle(tbxNameCarStyleDSHX.Text) == false)
            {
                tbxNameCarStyleDSHX.Foreground = Brushes.Red;
                tblNameCarStyleDSHX.Text = "Tên Hiệu Xe không hợp lệ!";
            }
            else
            {
                tbxNameCarStyleDSHX.Foreground = Brushes.Black;
                tblNameCarStyleDSHX.Text = null;
            }
        }

        private void tbxProductCountryDSHX_LostFocus(object sender, RoutedEventArgs e)
        {
            if (tbxProductCountryDSHX.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationDSX.CheckProductCountry(tbxProductCountryDSHX.Text) == false)
            {
                tbxProductCountryDSHX.Foreground = Brushes.Red;
                tblProductCountryDSHX.Text = "Tên Nước Sản Xuất không hợp lệ!";
            }
            else
            {
                tbxProductCountryDSHX.Foreground = Brushes.Black;
                tblProductCountryDSHX.Text = null;
            }
        }

        private void tbxNoteDSHX_LostFocus(object sender, RoutedEventArgs e)
        {
            if (tbxNoteDSHX.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationDSX.CheckNote(tbxNoteDSHX.Text) == false)
            {
                tbxNoteDSHX.Foreground = Brushes.Red;
                tblNoteDSHX.Text = "Ghi Chú không hợp lệ!";
            }
            else
            {
                tbxNoteDSHX.Foreground = Brushes.Black;
                tblNoteDSHX.Text = null;
            }
        }

        #endregion

        #region Process Button

        private void btnNewDSHX_Click(object sender, RoutedEventArgs e)
        {
            tbxNameCarStyleDSHX.Text = null;
            tbxNameCarStyleDSHX.IsReadOnly = false;
            tbxNameCarStyleDSHX.Foreground = Brushes.Black;
            tblNameCarStyleDSHX.Text = null;

            tbxProductCountryDSHX.Text = null;
            tbxProductCountryDSHX.IsReadOnly = false;
            tbxProductCountryDSHX.Foreground = Brushes.Black;
            tblProductCountryDSHX.Text = null;

            tbxNoteDSHX.Text = null;
            tbxNoteDSHX.Foreground = Brushes.Black;
            tbxNoteDSHX.IsReadOnly = false;
            tblNoteDSHX.Text = null;

            m_checkValidationDSX.SetAllCheckFalse();

            btnAddDSHX.IsEnabled = true;
            btnFixDSHX.IsEnabled = false;
            btnDeleteDSHX.IsEnabled = false;

            dataGrid1DSHX.SelectedIndex = -1;
        }

        private void btnAddDSHX_Click(object sender, RoutedEventArgs e)
        {
            if (m_checkValidationDSX.CheckAllCarStyle() == false)
            {
                MessageBox.Show("Vui lòng sửa lại thông tin cho đúng!");
                return;
            }

            
            if ((m_database.ADDHIEUXE(tbxNameCarStyleDSHX.Text,
                                                tbxProductCountryDSHX.Text,
                                                tbxNoteDSHX.Text)) == 1)
            {
                return;
            }

            btnAddDSHX.IsEnabled = false;
            btnDeleteDSHX.IsEnabled = true;
            btnFixDSHX.IsEnabled = true;
            tbxNameCarStyleDSHX.IsReadOnly = true;

            m_database.SubmitChanges();

            DataTable dt = new DataTable();
            dt = m_utilities.LINQToDataTable(m_database.LOADHIEUXE());
            dataGrid1DSHX.ItemsSource = dt.DefaultView;
        }

        private void btnFixDSHX_Click(object sender, RoutedEventArgs e)
        {
            if (m_checkValidationDSX.CheckAllCarStyle() == false)
                        {
                            MessageBox.Show("Vui lòng sửa lại thông tin cho đúng!");
                            return;
                        }
            
                        WindowYesNo window = new WindowYesNo();
                        window.lbError.Content = "Bạn có thực sự muốn sửa dữ liệu?";
                        window.ShowDialog();
            
                        if (window.Tag.ToString() == "0")
                        {
                            return;
                        }
            
                        m_database.FIXHIEUXE(tbxNameCarStyleDSHX.Text,
                                                            tbxProductCountryDSHX.Text,
                                                            tbxNoteDSHX.Text);
            
                        dataGrid1DSHX.ItemsSource = m_database.LOADHIEUXE();
        }

        private void btnDeleteDSHX_Click(object sender, RoutedEventArgs e)
        {
            WindowYesNo window = new WindowYesNo();
            window.lbError.Content = "Bạn có thực sự muốn xóa dữ liệu?";
            window.ShowDialog();

            if (window.Tag.ToString() == "0")
            {
                return;
            }

            m_database.DELETEHIEUXE(tbxNameCarStyleDSHX.Text);

            tbxNameCarStyleDSHX.IsReadOnly = false;

            btnAddDSHX.IsEnabled = true;
            btnFixDSHX.IsEnabled = false;
            btnDeleteDSHX.IsEnabled = false;

            dataGrid1DSHX.ItemsSource = m_database.LOADHIEUXE();
        }

        #endregion

        #region Process DataGrid

        private void dataGrid1DSHX_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataRowView dtGridRowView = (sender as DataGrid).SelectedItem as DataRowView;

            if (dtGridRowView == null)
            {
                return;
            }

            tbxNameCarStyleDSHX.Text = dtGridRowView.Row[0].ToString();
            tbxNameCarStyleDSHX.Foreground = Brushes.Black;
            tblNameCarStyleDSHX.Text = null;
            tbxNameCarStyleDSHX.IsReadOnly = true;

            tbxProductCountryDSHX.Text = dtGridRowView.Row[1].ToString();
            tbxProductCountryDSHX.Foreground = Brushes.Black;
            tblProductCountryDSHX.Text = null;
            tbxProductCountryDSHX.IsReadOnly = false;

            tbxNoteDSHX.Text = dtGridRowView.Row[2].ToString();
            tbxNoteDSHX.Foreground = Brushes.Black;
            tblNoteDSHX.Text = null;
            tbxNoteDSHX.IsReadOnly = false;

            m_checkValidationDSX.SetAllCheckTrue();

            btnAddDSHX.IsEnabled = false;
            btnDeleteDSHX.IsEnabled = true;
            btnFixDSHX.IsEnabled = true;
        }

        #endregion

        #endregion

        #region Tab DSX

        #region Process Input

        private void tbxNumberPlateDSX_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxNumberPlateDSX.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationDSHX.CheckNumberPlate(tbxNumberPlateDSX.Text) == false)
            {
                tbxNumberPlateDSX.Foreground = Brushes.Red;
                tblNumberPlateDSX.Text = "Biển số không hợp lệ!";
            }
            else
            {
                tbxNumberPlateDSX.Foreground = Brushes.Black;
                tblNumberPlateDSX.Text = null;
            }
             * */
        }

        private void tbxNameCustomerDSX_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxNameCustomerDSX.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationDSHX.CheckNameCustomer(tbxNameCustomerDSX.Text) == false)
            {
                tbxNameCustomerDSX.Foreground = Brushes.Red;
                tblNameCustomerDSX.Text = "Tên Khách Hàng không hợp lệ!";
            }
            else
            {
                tbxNameCustomerDSX.Foreground = Brushes.Black;
                tblNameCustomerDSX.Text = null;
            }
             * */
        }

        private void tbxAddressDSX_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxAddressDSX.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationDSHX.CheckAddress(tbxAddressDSX.Text) == false)
            {
                tbxAddressDSX.Foreground = Brushes.Red;
                tblAddressDSX.Text = "Địa chỉ không hợp lệ!";
            }
            else
            {
                tbxAddressDSX.Foreground = Brushes.Black;
                tblAddressDSX.Text = null;
            }*/
        }

        private void tbxNumberPhoneDSX_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxNumberPhoneDSX.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationDSHX.CheckNumberPhone(tbxNumberPhoneDSX.Text) == false)
            {
                tbxNumberPhoneDSX.Foreground = Brushes.Red;
                tblNumberPhoneDSX.Text = "Số điện thoại không hợp lệ!";
            }
            else
            {
                tbxNumberPhoneDSX.Foreground = Brushes.Black;
                tblNumberPhoneDSX.Text = null;
            }*/
        }

        private void tbxEmailDSX_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxEmailDSX.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationDSHX.CheckEmail(tbxEmailDSX.Text) == false)
            {
                tbxEmailDSX.Foreground = Brushes.Red;
                tblEmailDSX.Text = "Địa chỉ Email không hợp lệ!";
            }
            else
            {
                tbxEmailDSX.Foreground = Brushes.Black;
                tblEmailDSX.Text = null;
            }*/
        }

        #endregion

        #region Process Button

        private void btnNewDSX_Click(object sender, RoutedEventArgs e)
        {
            tbxNumberPlateDSX.Text = null;
            tbxNumberPlateDSX.Foreground = Brushes.Black;
            tbxNumberPlateDSX.IsReadOnly = false;
            tblNumberPlateDSX.Text = null;

            tbxNameCustomerDSX.Text = null;
            tbxNameCustomerDSX.Foreground = Brushes.Black;
            tbxNameCustomerDSX.IsReadOnly = false;
            tblNameCustomerDSX.Text = null;


            tbxAddressDSX.Text = null;
            tbxAddressDSX.Foreground = Brushes.Black;
            tbxAddressDSX.IsReadOnly = false;
            tblAddressDSX.Text = null;


            tbxNumberPhoneDSX.IsReadOnly = false;
            tbxNumberPhoneDSX.Foreground = Brushes.Black;
            tbxNumberPlateDSX.Text = null;
            tblNumberPhoneDSX.Text = null;

            tbxEmailDSX.Text = null;
            tbxEmailDSX.Foreground = Brushes.Black;
            tbxEmailDSX.IsReadOnly = false;
            tblEmailDSX.Text = null;


            tbxDebitDSX.Text = "0";
            //m_checkValidationDSHX.SetAllCheckFalse();

            btnAddDSX.IsEnabled = true;
            btnDeleteDSX.IsEnabled = false;
            btnFixDSX.IsEnabled = false;
        }

        private void btnAddDSX_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (m_checkValidationDSHX.CheckAllCar() == false)
            {
                MessageBox.Show("Vui lòng sửa lại thông tin cho đúng!");
                return;
            }

            if (m_carBusiness.SetDataCar(tbxNumberPlateDSX.Text,
                                    tbxNameCustomerDSX.Text,
                                    cbxGenderDSX.Text,
                                    cbxCarStyleDSX.Text,
                                    tbxAddressDSX.Text,
                                    tbxNumberPhoneDSX.Text,
                                    tbxEmailDSX.Text,
                                    Convert.ToDouble(tbxDebitDSX.Text)) == false)
            {
                return;
            }

            btnAddDSX.IsEnabled = false;
            btnDeleteDSX.IsEnabled = true;
            btnFixDSX.IsEnabled = true;

            tbxNumberPlateDSX.IsReadOnly = true;

            dataGrid1DSX.ItemsSource = m_carBusiness.GetDataCar().DefaultView;*/
        }

        private void btnFixDSX_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (m_checkValidationDSHX.CheckAllCar() == false)
            {
                MessageBox.Show("Vui lòng sửa lại thông tin cho đúng!");
                return;
            }

            WindowYesNo window = new WindowYesNo();
            window.lbError.Content = "Bạn có thực sự muốn sửa dữ liệu?";
            window.ShowDialog();

            if (window.Tag.ToString() == "0")
            {
                return;
            }

            m_carBusiness.FixDataCar(tbxNumberPlateDSX.Text,
                                    tbxNameCustomerDSX.Text,
                                    cbxGenderDSX.Text,
                                    cbxCarStyleDSX.Text,
                                    tbxAddressDSX.Text,
                                    tbxNumberPhoneDSX.Text,
                                    tbxEmailDSX.Text);

            dataGrid1DSX.ItemsSource = m_carBusiness.GetDataCar().DefaultView;*/
        }

        private void btnDeleteDSX_Click(object sender, RoutedEventArgs e)
        {
            /*
            WindowYesNo window = new WindowYesNo();
            window.lbError.Content = "Bạn có thực sự muốn xóa dữ liệu?";
            window.ShowDialog();

            if (window.Tag.ToString() == "0")
            {
                return;
            }

            m_carBusiness.DeleteDataCar(tbxNumberPlateDSX.Text);


            tbxNumberPlateDSX.IsReadOnly = false;

            btnAddDSX.IsEnabled = true;
            btnFixDSX.IsEnabled = false;
            btnDeleteDSX.IsEnabled = false;

            dataGrid1DSX.ItemsSource = m_carBusiness.GetDataCar().DefaultView;*/
        }

        private void btnOtherCarStyleDSX_Click(object sender, RoutedEventArgs e)
        {
            tabControlMain.SelectedIndex = 0;
        }

        #endregion

        #region Process DataGrid

        private void dataGrid1DSX_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            /*
            DataRowView dtGridRowView = (sender as DataGrid).SelectedItem as DataRowView;

            if (dtGridRowView == null)
            {
                return;
            }

            tbxNumberPlateDSX.Text = dtGridRowView.Row[0].ToString();
            tbxNumberPlateDSX.IsReadOnly = true;
            tbxNumberPlateDSX.Foreground = Brushes.Black;
            tblNumberPlateDSX.Text = null;


            tbxNameCustomerDSX.Text = dtGridRowView.Row[1].ToString();
            tbxNameCustomerDSX.IsReadOnly = false;
            tbxNameCustomerDSX.Foreground = Brushes.Black;
            tblNameCustomerDSX.Text = null;

            if (dtGridRowView.Row[2].ToString() == "Nam")
            {
                cbxGenderDSX.SelectedIndex = 0;
            }
            else
            {
                cbxGenderDSX.SelectedIndex = 1;
            }

            int i = 0;
            while (((DataRowView)cbxCarStyleDSX.Items[i]).Row[0].ToString() != dtGridRowView.Row[3].ToString())
            {
                ++i;
            }
            cbxCarStyleDSX.SelectedIndex = i;

            tbxAddressDSX.Text = dtGridRowView.Row[4].ToString();
            tbxAddressDSX.IsReadOnly = false;
            tbxAddressDSX.Foreground = Brushes.Black;
            tblAddressDSX.Text = null;

            tbxNumberPhoneDSX.Text = dtGridRowView.Row[5].ToString();
            tbxNumberPhoneDSX.IsReadOnly = false;
            tbxNumberPhoneDSX.Foreground = Brushes.Black;
            tblNumberPhoneDSX.Text = null;

            tbxEmailDSX.Text = dtGridRowView.Row[6].ToString();
            tbxEmailDSX.IsReadOnly = false;
            tbxEmailDSX.Foreground = Brushes.Black;
            tblEmailDSX.Text = null;

            m_checkValidationDSHX.SetAllCheckTrue();

            btnAddDSX.IsEnabled = false;
            btnDeleteDSX.IsEnabled = true;
            btnFixDSX.IsEnabled = true;*/
        }

        #endregion

        #endregion

        #region Tab TNBT

        #region Process Input

        private void tbxNumberPlateTNBT_GotFocus(object sender, RoutedEventArgs e)
        {
            tbxNameCustomerTNBT.IsReadOnly = true;
            tbxAddressTNBT.IsReadOnly = true;
            tbxNumberPhoneTNBT.IsReadOnly = true;
            tbxEmailTNBT.IsReadOnly = true;
        }

        private void tbxNumberPlateTNBT_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxNumberPlateTNBT.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationTNBT.CheckNumberPlate(tbxNumberPlateTNBT.Text) == false)
            {
                tbxNumberPlateTNBT.Foreground = Brushes.Red;
                tblNumberPlateTNBT.Text = "Biển số không hợp lệ!";
            }
            else
            {
                tbxNumberPlateTNBT.Foreground = Brushes.Black;
                tblNumberPlateTNBT.Text = null;
            }*/
        }

        private void tbxNameCustomerTNBT_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxNameCustomerTNBT.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationTNBT.CheckNameCustomer(tbxNameCustomerTNBT.Text) == false)
            {
                tbxNameCustomerTNBT.Foreground = Brushes.Red;
                tblNameCustomerTNBT.Text = "Tên Khách Hàng không hợp lệ!";
            }
            else
            {
                tbxNameCustomerTNBT.Foreground = Brushes.Black;
                tblNameCustomerTNBT.Text = null;
            }*/
        }

        private void tbxAddressTNBT_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxAddressTNBT.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationTNBT.CheckAddress(tbxAddressTNBT.Text) == false)
            {
                tbxAddressTNBT.Foreground = Brushes.Red;
                tblAddressTNBT.Text = "Địa Chỉ không hợp lệ!";
            }
            else
            {
                tbxAddressTNBT.Foreground = Brushes.Black;
                tblAddressTNBT.Text = null;
            }*/
        }

        private void tbxNumberPhoneTNBT_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxNumberPhoneTNBT.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationTNBT.CheckNumberPhone(tbxNumberPhoneTNBT.Text) == false)
            {
                tbxNumberPhoneTNBT.Foreground = Brushes.Red;
                tblNumberPhoneTNBT.Text = "Số điện thoại không hợp lệ!";
            }
            else
            {
                tbxNumberPhoneTNBT.Foreground = Brushes.Black;
                tblNumberPhoneTNBT.Text = null;
            }*/
        }

        private void tbxEmailTNBT_LostFocus(object sender, RoutedEventArgs e)
        {
            /*
            if (tbxEmailTNBT.IsReadOnly == true)
            {
                return;
            }

            if (m_checkValidationTNBT.CheckEmail(tbxEmailTNBT.Text) == false)
            {
                tbxEmailTNBT.Foreground = Brushes.Red;
                tblEmailTNBT.Text = "Địa Chỉ Email không hợp lệ!";
            }
            else
            {
                tbxEmailTNBT.Foreground = Brushes.Black;
                tblEmailTNBT.Text = null;
            }*/
        }

        #endregion

        #region Process Button

        private void btnNewTNBT_Click(object sender, RoutedEventArgs e)
        {
            tbxNumberPlateTNBT.Text = null;
            tbxNumberPlateTNBT.Foreground = Brushes.Black;
            tbxNumberPlateTNBT.IsReadOnly = false;
            tblNumberPlateTNBT.Text = null;

            tbxNameCustomerTNBT.Text = null;
            tbxNameCustomerTNBT.Foreground = Brushes.Black;
            tbxNameCustomerTNBT.IsReadOnly = true;
            tblNameCustomerTNBT.Text = null;

            tbxAddressTNBT.Text = null;
            tbxAddressTNBT.Foreground = Brushes.Black;
            tbxAddressTNBT.IsReadOnly = true;
            tblAddressTNBT.Text = null;

            tbxNumberPhoneTNBT.Text = null;
            tbxNumberPhoneTNBT.Foreground = Brushes.Black;
            tbxNumberPhoneTNBT.IsReadOnly = true;
            tblNumberPhoneTNBT.Text = null;

            tbxEmailTNBT.Text = null;
            tbxEmailTNBT.Foreground = Brushes.Black;
            tbxEmailTNBT.IsReadOnly = true;
            tblEmailTNBT.Text = null;

            tbxDebitTNBT.Text = "0";

            dpkReceiveCarTNBT.SelectedDate = DateTime.Now;

            tpkReceiveCarTNBT.SelectedTime = DateTime.Now.TimeOfDay;

            btnCheckTNBT.IsEnabled = true;
            btnCheckTNBT.Tag = "0";

            btnAddTNBT.IsEnabled = true;
            btnFixTNBT.IsEnabled = false;
            btnDeleteTNBT.IsEnabled = false;

            //m_checkValidationTNBT.SetAllCheckFalse();
        }

        private void btnAddTNBT_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (m_checkValidationTNBT.CheckAllCar() == false)
            {
                MessageBox.Show("Vui lòng sửa lại thông tin cho đúng!");

                return;
            }

            if (btnCheckTNBT.Tag.ToString() == "0")
            {
                m_carBusiness.SetDataCar(tbxNumberPlateTNBT.Text,
                                         tbxNameCustomerTNBT.Text,
                                         cbxGenderTNBT.Text,
                                         cbxCarStyleTNBT.Text,
                                         tbxAddressTNBT.Text,
                                         tbxNumberPhoneTNBT.Text,
                                         tbxEmailTNBT.Text,
                                         Convert.ToDouble(tbxDebitTNBT.Text));
            }

            if (m_receiveCarBusiness.SetDataReceiveCar(tbxNumberPlateTNBT.Text,
                                                       dpkReceiveCarTNBT.SelectedDate.ToString(),
                                                       tpkReceiveCarTNBT.SelectedTime.ToString()) == false)
            {
                return;
            }

            dataGrid1TNBT.ItemsSource = m_receiveCarBusiness.GetDataReceiveCar().DefaultView;

            tbxNumberPlateTNBT.IsReadOnly = true;
            dpkReceiveCarTNBT.IsEnabled = false;
            tpkReceiveCarTNBT.IsEnabled = false;

            btnDeleteTNBT.IsEnabled = true;
            btnFixTNBT.IsEnabled = true;
            btnAddTNBT.IsEnabled = false;*/
        }

        private void btnFixTNBT_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (m_checkValidationTNBT.CheckAllCar() == false)
            {
                MessageBox.Show("Vui lòng sửa lại thông tin cho đúng!");
                return;
            }

            WindowYesNo window = new WindowYesNo();
            window.lbError.Content = "Bạn có thực sự muốn sửa dữ liệu?";
            window.ShowDialog();

            if (window.Tag.ToString() == "0")
            {
                return;
            }

            m_carBusiness.FixDataCar(tbxNumberPlateTNBT.Text,
                                    tbxNameCustomerTNBT.Text,
                                    cbxGenderTNBT.Text,
                                    cbxCarStyleTNBT.Text,
                                    tbxAddressTNBT.Text,
                                    tbxNumberPhoneTNBT.Text,
                                    tbxEmailTNBT.Text);

            dataGrid1TNBT.ItemsSource = m_receiveCarBusiness.GetDataReceiveCar().DefaultView;*/
        }

        private void btnDeleteTNBT_Click(object sender, RoutedEventArgs e)
        {
            /*
            WindowYesNo window = new WindowYesNo();
            window.lbError.Content = "Bạn có thực sự muốn xóa dữ liệu?";
            window.ShowDialog();

            if (window.Tag.ToString() == "0")
            {
                return;
            }

            m_receiveCarBusiness.DeleteDataReceiveCar(tbxNumberPlateTNBT.Text,
                                                      dpkReceiveCarTNBT.DisplayDate.ToString(),
                                                      tpkReceiveCarTNBT.SelectedTime.ToString());

            tbxNumberPlateTNBT.IsReadOnly = false;
            dpkReceiveCarTNBT.IsEnabled = true;
            tpkReceiveCarTNBT.IsEnabled = true;

            btnAddTNBT.IsEnabled = true;
            btnFixTNBT.IsEnabled = false;
            btnDeleteTNBT.IsEnabled = false;

            dataGrid1TNBT.ItemsSource = m_receiveCarBusiness.GetDataReceiveCar().DefaultView;*/
        }

        private void CheckTNBT()
        {
            /*
            if (m_carBusiness.CheckNumberPlate(tbxNumberPlateTNBT.Text) == true)
            {
                btnCheckTNBT.Tag = "1";
                DataTable dTable = m_carBusiness.GetInformationFromNP(tbxNumberPlateTNBT.Text);

                tbxNameCustomerTNBT.Text = dTable.Rows[0]["TenKhachHang"].ToString();
                tbxNameCustomerTNBT.Foreground = Brushes.Black;
                tbxNameCustomerTNBT.IsReadOnly = true;
                tblNameCustomerTNBT.Text = null;

                if (dTable.Rows[0]["GioiTinh"].ToString() == "Nam")
                {
                    cbxGenderTNBT.SelectedIndex = 0;
                }
                else
                {
                    cbxGenderTNBT.SelectedIndex = 1;
                }

                int i = 0;
                while (((DataRowView)cbxCarStyleTNBT.Items[i]).Row[0].ToString() != dTable.Rows[0]["TenHieuXe"].ToString())
                {
                    ++i;
                }
                cbxCarStyleTNBT.SelectedIndex = i;

                tbxAddressTNBT.Text = dTable.Rows[0]["DiaChi"].ToString();
                tbxAddressTNBT.IsReadOnly = true;
                tbxAddressTNBT.Foreground = Brushes.Black;
                tblAddressTNBT.Text = null;

                tbxNumberPhoneTNBT.Text = dTable.Rows[0]["DienThoai"].ToString();
                tbxNumberPlateTNBT.IsReadOnly = true;
                tbxNumberPlateTNBT.Foreground = Brushes.Black;
                tblNumberPlateTNBT.Text = null;

                tbxEmailTNBT.Text = dTable.Rows[0]["Email"].ToString();
                tbxEmailTNBT.IsReadOnly = true;
                tbxEmailTNBT.Foreground = Brushes.Black;
                tblEmailTNBT.Text = null;

                tbxDebitTNBT.Text = dTable.Rows[0]["TienNo"].ToString();

                m_checkValidationTNBT.SetAllCheckTrue();
            }
            else
            {
                btnCheckTNBT.Tag = 0;

                tbxNameCustomerTNBT.IsReadOnly = false;
                tbxAddressTNBT.IsReadOnly = false;
                tbxNumberPhoneTNBT.IsReadOnly = false;
                tbxEmailTNBT.IsReadOnly = false;
            }*/
        }

        private void btnCheckTNBT_Click(object sender, RoutedEventArgs e)
        {
            CheckTNBT();
        }

        private void btnOtherCarStyleTNBT_Click(object sender, RoutedEventArgs e)
        {
            tabControlMain.SelectedIndex = 0;
        }

        #endregion

        #region Process DataGrid

        private void dataGrid1TNBT_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            /*
            DataRowView dtGridRowView = (sender as DataGrid).SelectedItem as DataRowView;

            if (dtGridRowView == null)
            {
                return;
            }

            tbxNumberPlateTNBT.Text = dtGridRowView.Row[0].ToString();
            tbxNumberPlateTNBT.IsReadOnly = true;
            tbxNumberPlateTNBT.Foreground = Brushes.Black;
            tblNumberPlateTNBT.Text = null;

            int i = 0;
            while (((DataRowView)cbxCarStyleTNBT.Items[i]).Row[0].ToString() != dtGridRowView.Row[1].ToString())
            {
                ++i;
            }
            cbxCarStyleTNBT.SelectedIndex = i;

            tbxNameCustomerTNBT.Text = dtGridRowView.Row[2].ToString();
            tbxNameCustomerTNBT.IsReadOnly = false;
            tbxNameCustomerTNBT.Foreground = Brushes.Black;
            tblNameCustomerTNBT.Text = null;

            if (dtGridRowView.Row[3].ToString() == "Nam")
            {
                cbxGenderTNBT.SelectedIndex = 0;
            }
            else
            {
                cbxGenderTNBT.SelectedIndex = 1;
            }

            tbxAddressTNBT.Text = dtGridRowView.Row[4].ToString();
            tbxAddressTNBT.IsReadOnly = false;
            tbxAddressTNBT.Foreground = Brushes.Black;
            tblAddressTNBT.Text = null;

            tbxNumberPhoneTNBT.Text = dtGridRowView.Row[5].ToString();
            tbxNumberPhoneTNBT.IsReadOnly = false;
            tbxNumberPhoneTNBT.Foreground = Brushes.Black;
            tblNumberPhoneTNBT.Text = null;

            tbxEmailTNBT.Text = dtGridRowView.Row[6].ToString();
            tbxEmailTNBT.IsReadOnly = false;
            tbxEmailTNBT.Foreground = Brushes.Black;
            tblEmailTNBT.Text = null;

            dpkReceiveCarTNBT.SelectedDate = Convert.ToDateTime(dtGridRowView.Row[8].ToString());
            dpkReceiveCarTNBT.IsEnabled = false;

            tpkReceiveCarTNBT.SelectedTime = (TimeSpan)(dtGridRowView.Row[9]);
            tpkReceiveCarTNBT.IsEnabled = false;

            m_checkValidationTNBT.SetAllCheckTrue();

            btnAddTNBT.IsEnabled = false;
            btnDeleteTNBT.IsEnabled = true;
            btnFixTNBT.IsEnabled = true;*/
        }

        #endregion

        #endregion

        #region Tab DSPSC

        #region Process Input

        private void cbxNumberPlateDSPSC_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            /*
            if (cbxNumberPlateDSPSC.SelectedIndex == -1)
            {
                cbxNumberPlateDSPSC.SelectedIndex = 0;
            }

            if (cbxNumberPlateDSPSC.Text != "" && cbxNumberPlateDSPSC.Text != null)
            {
                DataTable dTable = m_carBusiness.GetInformationFromNP(cbxNumberPlateDSPSC.Text);

                tbxNameCustomerDSPSC.Text = dTable.Rows[0]["TenKhachHang"].ToString();

                tbxGenderDSPSC.Text = dTable.Rows[0]["GioiTinh"].ToString();


                tbxNameCarStyleDSPSC.Text = dTable.Rows[0]["TenHieuXe"].ToString();

                tbxAddressDSPSC.Text = dTable.Rows[0]["DiaChi"].ToString();

                tbxNumberPhoneDSPSC.Text = dTable.Rows[0]["DienThoai"].ToString();

                tbxEmailDSPSC.Text = dTable.Rows[0]["Email"].ToString();

                tbxDebitDSPSC.Text = dTable.Rows[0]["TienNo"].ToString();
            }*/
        }

        #endregion

        #region Tab Process Button

        private void btnNewDSPSC_Click(object sender, RoutedEventArgs e)
        {
            /*
            tbxIDDSPSX.Text = m_utiAutoID.NextID(m_listRepairBillBusiness.GetLastIDListRepairBill(), "MaPSC");

            dpkRepairLPSC.SelectedDate = DateTime.Now;
            tbxTotalCashDSPSC.Text = "0";

            tbxNameCustomerDSPSC.Text = null;
            tbxGenderDSPSC.Text = null;
            tbxAddressDSPSC.Text = null;
            tbxNumberPhoneDSPSC.Text = null;
            tbxEmailDSPSC.Text = null;
            tbxDebitDSPSC.Text = "0";

            btnInfoDSPSC.IsEnabled = false;
            btnAddDSPSC.IsEnabled = true;
            btnDeleteDSPSC.IsEnabled = false;
            btnFixDSPSC.IsEnabled = false;*/
        }

        private void btnAddDSPSC_Click(object sender, RoutedEventArgs e)
        {
//             m_listRepairBillBusiness.SetDataListRepairBill(tbxIDDSPSX.Text,
//                                                            cbxNumberPlateDSPSC.Text,
//                                                            dpkRepairDSPSC.SelectedDate.ToString());

            btnAddDSPSC.IsEnabled = false;
            btnDeleteDSPSC.IsEnabled = true;
            btnFixDSPSC.IsEnabled = true;
            btnInfoDSPSC.IsEnabled = true;

            //dataGrid1DSPSC.ItemsSource = m_listRepairBillBusiness.GetDataListRepairBill().DefaultView;
        }

        private void btnFixDSPSC_Click(object sender, RoutedEventArgs e)
        {
//             m_listRepairBillBusiness.FixDataListRepairBill(tbxIDDSPSX.Text,
//                                                            cbxNumberPlateDSPSC.Text,
//                                                            dpkRepairDSPSC.SelectedDate.ToString());

            //dataGrid1DSPSC.ItemsSource = m_listRepairBillBusiness.GetDataListRepairBill().DefaultView;
        }

        private void btnDeleteDSPSC_Click(object sender, RoutedEventArgs e)
        {
            //m_listRepairBillBusiness.DeleteDataListRepairBill(tbxIDDSPSX.Text);

            btnInfoDSPSC.IsEnabled = false;
            btnFixDSPSC.IsEnabled = false;
            btnAddDSPSC.IsEnabled = true;

            //dataGrid1DSPSC.ItemsSource = m_listRepairBillBusiness.GetDataListRepairBill().DefaultView;
        }

        private void btnInfoDSPSC_Click(object sender, RoutedEventArgs e)
        {

        }

        #endregion

        #region Process DataGrid

        #endregion

        #endregion
    }
}
